home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / emulator / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / Assemblers / 68kasm / include.c < prev    next >
C/C++ Source or Header  |  1995-07-26  |  2KB  |  73 lines

  1. /******************************************************************************
  2.  * $Id: include.c,v 1.3 1995/01/13 00:38:29 bmott Exp $
  3.  ******************************************************************************
  4.  *
  5.  * Handle INCLUDE directives in the source code
  6.  *
  7.  ******************************************************************************
  8.  * $Log: include.c,v $
  9.  * Revision 1.3  1995/01/13  00:38:29  bmott
  10.  * Fixed a stupid problem!
  11.  *
  12.  * Revision 1.2  1995/01/01  05:37:23  bmott
  13.  * Fixed problem with INCLUDE having to be in uppercase
  14.  *
  15.  * Revision 1.1  1994/09/21  22:29:26  bmott
  16.  * Initial revision
  17.  *
  18.  *****************************************************************************/
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22.  
  23.  
  24. char* buildCompleteSourceFile(FILE* currentFile, char* currentFileName, 
  25.     FILE* completeFile, int level)
  26. {
  27.   FILE* includeFile;
  28.  
  29.   char buffer[8192], directive[1024], operand[1024], *error;
  30.  
  31.   /* Make sure we don't loop forever */
  32.   if(level>15)
  33.     return("Too many nested INCLUDEs\n");
  34.  
  35.   while(1)
  36.   {
  37.     fgets(buffer,sizeof(buffer),currentFile);
  38.     if(feof(currentFile))
  39.       break;
  40.    
  41.     if(sscanf(buffer,"%s %s", directive, operand) == 2)
  42.     {
  43.       if(strcasecmp(directive,"INCLUDE")==0)
  44.       {
  45.         includeFile=fopen(operand,"r");
  46.         if(!includeFile)
  47.         {
  48.           char* tmp = (char*)malloc(256);
  49.           sprintf(tmp,"Could not find INCLUDE file: %s\n  for file: %s\n",
  50.               operand, currentFileName);
  51.           return(tmp);
  52.         }
  53.         
  54.         error = buildCompleteSourceFile(includeFile, operand, completeFile,
  55.             level+1);
  56.         fclose(includeFile);
  57.         if(error)
  58.           return(error);
  59.       }
  60.       else
  61.       {
  62.         fprintf(completeFile,"%s", buffer);
  63.       }
  64.     }
  65.     else
  66.     {
  67.         fprintf(completeFile,"%s", buffer);
  68.     }
  69.   }
  70.   return(NULL);
  71. }
  72.  
  73.